package org.bootstrap.service.Impl;

import cn.hutool.core.lang.Console;
import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.bootstrap.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;


@Service
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    private UserServiceAdminImpl userService;

    @Override
    public JSONObject table(HashMap<String, String> params) {
        JSONObject obj = JSONUtil.createObj();
        int code = 400;
        String msg = "not result";
        if (MapUtil.isNotEmpty(params)) {
            // 检查请求是否有权限
            JSONObject verity = userService.verity_admin(params);
            if (verity.containsKey("is_admin") && verity.getBool("is_admin")) {
                code = 200;
                msg = "权限认证成功，当前是管理员权限";
            } else {
                msg = verity.getStr("msg");
            }
        }
        obj.putOpt("code", code)
                .putOpt("msg", msg);
        return obj;
    }
}
